home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 016a / frbts_20.zip / FRGET.C < prev    next >
C/C++ Source or Header  |  1991-04-27  |  8KB  |  310 lines

  1. /****************************************************************************/
  2. /*                                                                          */
  3. /*    Fget.c      Version 2.0    By Craig Derouen                           */
  4. /*                Add on util for Frobot.                                   */
  5. /*                                                                          */
  6. /*                                                                          */
  7. /****************************************************************************/
  8.  
  9. /*  This version is written in Microsoft C 6.0. Version 1.x was Microsoft
  10.     C 5.X but I lost the source code so I had to re-write this the hard
  11.     way!
  12.    
  13. */
  14.  
  15. #include "frobot.h"
  16.  
  17. #include "share.h"
  18.  
  19. char temp[100];
  20. char temp1[100];
  21.  
  22. struct stat fbuf;
  23.  
  24. char ScriptFile[65];
  25.  
  26. char ScrCmnd[5];
  27. char FileName[66];
  28. char NodeStr[20];
  29. char DateStr[20];
  30. char TimeStr[20];
  31. char ScrMode[5];
  32. char ScrTimes[5];
  33.  
  34. char hdir[_MAX_DIR];
  35. char hdrive[_MAX_DRIVE];
  36.  
  37. int  ExitCode;
  38. int  ShowActivity = TRUE;
  39. int  Silent = FALSE;
  40.  
  41. int getparms(char *ctlfile);
  42. int checkparms(void);
  43. void promptparms(void);
  44. void writeparms(void);
  45. void striptail(char *p);
  46.  
  47. int main(int argc,char **argv)
  48. {
  49.    char strng[65];
  50.  
  51. /* Parse out the drive and dir where frobot is located */
  52.    _splitpath(argv[0],hdrive,hdir,temp,temp1);        /* Ignore name and extension */
  53.  
  54.    strcpy(strng,"Frobot.ctl");        /* Try current dir first */
  55.    if(stat(strng,&fbuf) == -1) {        /* Not there, try fget dir */
  56.       _makepath(strng,hdrive,hdir,"Frobot",".CTL");
  57.       if(stat(strng,&fbuf) == -1) {        /* Not there, try Binkley env */
  58.          strcpy(strng,getenv("BINKLEY"));
  59.          if (!*strng) {
  60.             printf("Missing Frobot parameter file\n");
  61.             warble();
  62.             exit(1);
  63.          }
  64.          striptail(strng);
  65.          strcat(strng,"\\Frobot.ctl");
  66.          if(stat(strng,&fbuf) == -1) {    /* Not there, give up */
  67.             printf("Missing Frobot parameter file\n");
  68.             warble();
  69.             exit(1);
  70.          }
  71.       }
  72.    }
  73.  
  74.    if(getparms(strng)) {
  75.       printf("Error processing Frobot parameter file\n");
  76.       warble();
  77.       ExitCode = 1;
  78.    }
  79.    if (argc >= 7) {        /* It's on the command line */
  80.       strcpy(ScrCmnd,argv[1]);
  81.       strcpy(FileName,argv[2]);
  82.       strcpy(NodeStr,argv[3]);
  83.       strcpy(DateStr,argv[4]);
  84.       strcpy(TimeStr,argv[5]);
  85.       strcpy(ScrMode,argv[6]);
  86.       if (argc >= 8)
  87.          strcpy(ScrTimes,argv[7]);
  88.    }
  89.    else if(argc < 2)     /* We must do a prompt mode */
  90.       promptparms();
  91.    if(checkparms()) {
  92.       printf("Invalid parameters, exiting\n");
  93.       warble();
  94.       ExitCode = 1;
  95.    }
  96.    else writeparms();
  97.    return(ExitCode);
  98. }
  99.  
  100. /* Parse out the parameter file */
  101. int getparms(char *ctlfile)
  102. {
  103.    FILE *infile;
  104.    char *p1,*p2;
  105.    int checkcount = 0;
  106.  
  107.    if ((infile = _fsopen(ctlfile,"rt",SH_DENYNO)) == NULL)
  108.       return(TRUE);        /* Say there's an error */
  109.  
  110.    fgets(temp,81,infile);
  111.    while (!feof(infile)) {
  112.       if (*temp) {        /* Parse out token string */
  113.          p1 = strtok(temp," \n\t");
  114.          p2 = strtok(NULL," \n\t;");
  115.          if (*p1 == ';') {        /* Just ignore comment lines */
  116.             fgets(temp,81,infile);
  117.             continue;
  118.          }
  119.          if (strcmpi(p1,"scriptloc") == 0) {
  120.             if (p2) {
  121.                strcpy(ScriptFile,p2);
  122.                checkcount++;
  123.             }
  124.          }
  125.          else if (strcmpi(p1,"bells") == 0) {
  126.             if (p2){
  127.                if (strcmpi(p2,"Yes") == 0)
  128.                   Silent = FALSE;
  129.                else Silent = TRUE;
  130.             }
  131.          }
  132.       }
  133.       fgets(temp,81,infile);
  134.    }
  135.    fclose(infile);
  136.    if (checkcount < 1)
  137.       return(2);        /* Not all the necessary parameters were found */
  138.    return(FALSE);
  139. }
  140.  
  141. /* Test the validity of parameters */
  142. int checkparms(void)
  143. {
  144.    int x;
  145.  
  146. /* Check out command mode */
  147.    x = strlen(ScrCmnd);
  148.    if (x > 2 || x < 1)
  149.       return 1;
  150.  
  151.    x = tolower(*ScrCmnd);
  152.    if (x != 'r' && x != 's')
  153.       return 1;
  154.  
  155. /* Check out filename */
  156.    if(strlen(FileName) < 1)
  157.       return 1;
  158.    
  159. /* Check out net/node */
  160.    if (strlen(NodeStr) < 3)
  161.       return 1;
  162.    if (strchr(NodeStr,'/') == NULL)
  163.       return 1;
  164.  
  165. /* Check out the date */
  166.    if (strchr(DateStr,'/') == NULL) {        /* It's a special macro */
  167.       if (strlen(DateStr) < 3)
  168.          return 1;
  169.  
  170.       x = TRUE;        /* Assume it's bad */
  171.       strncpy(temp,DateStr,3);        /* We only need 3 for testing */
  172.       temp[3] = 0;
  173.       if (strcmpi(temp,"NOW") == 0)
  174.          x = FALSE;
  175.       else if (strcmpi(temp,"Sun") == 0)
  176.          x = FALSE;
  177.       else if (strcmpi(temp,"Mon") == 0)
  178.          x = FALSE;
  179.       else if (strcmpi(temp,"Tue") == 0)
  180.          x = FALSE;
  181.       else if (strcmpi(temp,"Wed") == 0)
  182.          x = FALSE;
  183.       else if (strcmpi(temp,"Thu") == 0)
  184.          x = FALSE;
  185.       else if (strcmpi(temp,"Fri") == 0)
  186.          x = FALSE;
  187.       else if (strcmpi(temp,"Sat") == 0)
  188.          x = FALSE;
  189.  
  190.       if (x) return 1;
  191.    }
  192.    else if (strlen(DateStr) > 8 || strlen(DateStr) < 5)
  193.       return 1;
  194.  
  195. /* Check out the time */
  196.    if (strchr(TimeStr,':') == NULL) {        /* It's a special macro */
  197.       if (strcmpi(TimeStr,"NOW") != 0)
  198.          return 1;
  199.    }
  200.    else if (strlen(TimeStr) > 5 || strlen(TimeStr) < 4)
  201.       return 1;
  202.  
  203. /* check out flo mode */
  204.    if (strlen(ScrMode) > 1)
  205.       return 1;
  206.    x = tolower(*ScrMode);
  207.    if (x != 'c' && x != 'h' && x != 'd' && x != 'd')
  208.       return 1;
  209.  
  210.    return 0;
  211. }
  212.  
  213. void promptparms(void)
  214. {
  215.  
  216.    while (1) {
  217.       printf("Enter Script command. 'S' for send or 'R' for request file: ");
  218.       gets(temp);
  219.       blanktrim(temp);
  220.       if (*temp > '!') {
  221.          strcpy(ScrCmnd,temp);
  222.          break;
  223.       }
  224.    }
  225.    while (1) {
  226.       printf("Enter FileName: ");
  227.       gets(temp);
  228.       blanktrim(temp);
  229.       if (*temp > '!') {
  230.          strcpy(FileName,temp);
  231.          break;
  232.       }
  233.    }
  234.    while (1) {
  235.       printf("Enter Net/Node (Zone is optional but ignored): ");
  236.       gets(temp);
  237.       blanktrim(temp);
  238.       if (*temp > '!') {
  239.          strcpy(NodeStr,temp);
  240.          break;
  241.       }
  242.    }
  243.    while (1) {
  244.       printf("Enter start date (day of week,'NOW', or mm/dd/yr): ");
  245.       gets(temp);
  246.       blanktrim(temp);
  247.       if (*temp > '!') {
  248.          strcpy(DateStr,temp);
  249.          break;
  250.       }
  251.    }
  252.    while (1) {
  253.       printf("Enter start time ('NOW' or 24 hour format HH:MM): ");
  254.       gets(temp);
  255.       blanktrim(temp);
  256.       if (*temp > '!') {
  257.          strcpy(TimeStr,temp);
  258.          break;
  259.       }
  260.    }
  261.    while (1) {
  262.       printf("Enter flow mode. 'C' for crash,'D' for direct,'N' for normal\n");
  263.       printf("\t or 'H' for hold: ");
  264.       gets(temp);
  265.       blanktrim(temp);
  266.       if (*temp > '!') {
  267.          strcpy(ScrMode,temp);
  268.          break;
  269.       }
  270.    }
  271.    if ( tolower(*ScrCmnd) == 'r') {
  272.       printf("Enter # of times to request file: ");
  273.       gets(temp);
  274.       blanktrim(temp);
  275.       if (*temp)
  276.          strcpy(ScrTimes,temp);
  277.       else strcpy(ScrTimes,"1");
  278.    }
  279. }
  280.  
  281. void writeparms(void)
  282. {
  283.    FILE *fl;
  284.  
  285.    if ((fl = _fsopen(ScriptFile,"at",SH_DENYWR)) == NULL) {
  286.       printf("Error opening scriptfile: %s, exiting\n",ScriptFile);
  287.       warble();
  288.       exit(1);
  289.    }
  290.    fseek(fl,0L,SEEK_END);
  291.    sprintf(temp,"%s %s %s %s %s %s ",ScrCmnd,FileName,NodeStr,DateStr,TimeStr,ScrMode);
  292.    if (*ScrTimes)
  293.       strcat(temp,ScrTimes);
  294.    strcat(temp,"\n");
  295.    fputs(temp,fl);
  296.    fclose(fl);
  297. }
  298.  
  299. /* Check dirpath and remove tail dir sep if its there */
  300. void striptail(char *p)
  301. {
  302.    int x;
  303.  
  304.    x = strlen(p) - 1;
  305.    if (p[x] == '\\')
  306.       p[x] = 0;
  307. }
  308.  
  309.  
  310.